package com.xx.controller;

import com.xx.entity.Working;
import com.xx.service.WorkingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
/**
 * @author 许欣
 * 时间：2022/5/4 12:24
 * 描述：
 */
@Controller
@RequestMapping("/work")
public class WorkingController {
    @Resource
    private WorkingService workingService;

    @RequestMapping(value = "/list")
    public String findAll(Model model){
        model.addAttribute("list", workingService.findAll());
        return "list";
    }
    @RequestMapping(value = "/view/{id}")
    public String details(@PathVariable Integer id, Model model){
        model.addAttribute("listw", workingService.findById(id));
        return "view";
    }
    @RequestMapping("/toAdd")
    public String toAdd() {
        return "add";
    }
    @RequestMapping("add")
    public String add(Working working) {
        workingService.add(working);
        return "redirect:/work/list";
    }
    @RequestMapping(value = "/del/{id}")
    public String del(@PathVariable Integer id,Model model){
        workingService.del(id);
        return "redirect:/work/list";
    }

}
